package com.lankystar.logistucs.spring.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.lankystar.logistucs.spring.dao.IBrokerDao;

@Repository
public class BrokerDaoImpl extends BaseDaoImpl implements IBrokerDao {

	@Autowired
	private SessionFactory sf;
	
	public Session getSession(){
		System.out.println("session  BrokerDaoImpl!!");
		return sf.getCurrentSession();
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<Object[]> selectCargoAndTwoOrder(int brokerId) {
		String  sql = "from TwoOrder two left join two.tats tats join two.oneOrder one join one.cargos c join c.broker b where b.companyId = ?";
		List<Object[]> oblist = getSession().createQuery(sql).setInteger(0, brokerId).list();
		return oblist;
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<Object[]> selectRecelveOrder(int brokerId,String createTime) {
		String  sql = "from TwoOrder two left join two.tats tats join two.oneOrder one join one.cargos c join c.broker b where b.companyId = ?";
		if(createTime!=null&&createTime!=""){
			sql +=" and tats.createTime = "+Long.parseLong(createTime)+"";
		}
		List<Object[]> oblist = getSession().createQuery(sql).setInteger(0, brokerId).list();
		return oblist;
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<Object[]> selectOrderlist(int companyId) {
		String hql = "from TwoOrder two join two.oneOrder one join one.cargos c join c.broker b where b.companyId = ?";
		List<Object[]> oblist = getSession().createQuery(hql).setInteger(0, companyId).list();
		return oblist;
	}

}
